﻿
// Condition: 9. Write a methos that sorts an array in ascending / descending order.


using System;

class AscendDescend
{

    static int[] SortAscend(int[] array1 )
    {
        for (int i = 0; i < array1.Length - 1; i++)
        {
            for (int j = i + 1; j < array1.Length; j++)
            {
                if (array1[i] > array1[j])
                {
                    array1[i] = array1[i] + array1[j];
                    array1[j] = array1[i] - array1[j];
                    array1[i] = array1[i] - array1[j];
                }
            }
        }
        return array1;
    }

    static int[] SortDescend(int[] array1)
    {
        for (int i = 0; i < array1.Length - 1; i++)
        {
            for (int j = i + 1; j < array1.Length; j++)
            {
                if (array1[i] < array1[j])
                {
                    array1[i] = array1[i] + array1[j];
                    array1[j] = array1[i] - array1[j];
                    array1[i] = array1[i] - array1[j];
                }
            }
        }
        return array1;
    }

    static void Main(string[] args)
    {
        Console.Write("Enter number of elements in array: ");
        int num = int.Parse(Console.ReadLine());
        int[] array = new int[num];
        for (int k = 0; k < num; k++)
        {
            Console.Write("Element[{0}] : ", k);
            array[k] = int.Parse(Console.ReadLine());
        }
        Console.WriteLine("Initial array: ");
        for (int k = 0; k < array.Length; k++)
        {
            Console.Write(array[k] + " ");
        }
        Console.WriteLine();

        int[] sortArray = SortDescend(array);
        
        Console.Write("The sort array in descending order is: { ");
        for (int k = 0; k < sortArray.Length; k++)
        {
            Console.Write(array[k] + " ");
        }
        Console.Write("}");
        Console.WriteLine();

        sortArray = SortAscend(array);

        Console.Write("The sort array in ascending order is: { ");
        for (int k = 0; k < sortArray.Length; k++)
        {
            Console.Write(array[k] + " ");
        }
        Console.Write("}");
        Console.WriteLine();

    }
}

